home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.mactech.com 2010
/
ftp.mactech.com.tar
/
ftp.mactech.com
/
machack
/
Hacks96
/
RoasterJavaWAHTTPCGI.sit
/
Roaster-Java-WA-HTTP-CGI hack
/
JavaWebStuff
/
Messages.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-22
|
2KB
|
132 lines
#include <string.h>
#include <Gestalt.h>
#include <GestaltEqu.h>
#include "CoolGestalt.h"
#include <OSUtils.h>
#include "Messages.h"
typedef struct myQueue
{
QElemPtr qLink;
short qType;
Ptr qData;
} myQueue, *myQueuePtr;
OSErr MsgToQ(long qName, char *message, long len)
{
char *elt;
long g = 0;
OSErr status;
myQueuePtr header;
status = Gestalt(qName, &g);
if (status == noErr && g != 0)
{
elt = NewPtrSysClear(len);
if (elt)
{
header = (myQueuePtr) NewPtrSysClear(sizeof(myQueue));
if (header)
{
memcpy(elt, message, len);
header->qData = elt;
Enqueue((QElemPtr) header, (QHdrPtr) g);
status = 0;
}
else
{
status = -3;
DisposePtr(elt);
}
}
else
status = -2;
}
else
status = -1;
return status;
}
char *MsgFromQ(long qName)
{
long g = 0;
OSErr status;
Ptr result = NULL;
QHdrPtr q;
myQueuePtr header;
char *elt = NULL;
status = Gestalt(qName, &g);
if (status == noErr && g != 0)
{
q = (QHdrPtr) g;
header = (myQueuePtr) q->qHead;
if (header)
{
status = Dequeue((QElemPtr) header, q);
elt = header->qData;
DisposePtr((Ptr) header);
}
result = elt;
}
return result;
}
void FlushQ(long qName)
{
char *elt;
while ((elt = MsgFromQ(qName)) != NULL)
{
DisposePtr(elt);
}
}
OSErr SetupQueues()
{
long g;
OSErr status, result = noErr;
Ptr qHead;
status = Gestalt('javC', &g);
if (status != noErr || g == 0)
{
qHead = NewPtrSysClear(sizeof(QHdr));
if (!qHead)
return -1;
status = NewGestaltValue('javC', (long) qHead);
if (status != noErr)
result = status;
}
status = Gestalt('javS', &g);
if (status != noErr || g == 0)
{
qHead = NewPtrSysClear(sizeof(QHdr));
if (!qHead)
return -2;
status = NewGestaltValue('javS', (long) qHead);
if (status != noErr)
result = status;
}
return result;
}